package org.example.core.Service.impl;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.example.core.Service.FreeMarkerService;
import org.example.core.pojo.ComfyuiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;

@Service
public class FreeMarkerServiceImpl implements FreeMarkerService {
    @Autowired
    private Configuration configuration;
    @Override
    public String renderText2Image(ComfyuiModel model) throws IOException, TemplateException {
        Template template = configuration.getTemplate("t2i.ftlh");
        HashMap<String, Object> map = new HashMap<>();
        map.put("config",model);
        StringWriter stringWriter = new StringWriter();
        template.process(map,stringWriter);
        /**
         * 第一个参数是模版中要替换的值，第二个参数是替换后的结果要放入的对象
         */
        return stringWriter.toString();
    }
}
